package backstage.information.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import backstage.information.dao.InformationDao;
import backstage.information.pojo.Information;

public class InformationDaoImpl extends HibernateDaoSupport implements InformationDao {

	public void seva(Information i) {
		getHibernateTemplate().save(i);
	}

	public void update(Information i) {
		getHibernateTemplate().update(i);
	}
	
	public void delete(Information i) {
		getHibernateTemplate().delete(i);
	}

	public Information getInformation(Integer id) {
		return null;
	}

	public List<Information> getInformationList(String hql, Object[] values) {
		List<Information> list = getHibernateTemplate().find(hql,values);
		return list;
	}
	
	public void set(){
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		Query query = session.createSQLQuery("select IFNULL(max(indexs),0) from staff_info where staffid=? and infoid=?");
		query.setInteger(0, 2);
		query.setInteger(1, 2);
		List l = query.list();
		Integer i = new Integer(l.get(0).toString());
		if(i != 0) i+=i;
		query = session.createSQLQuery("insert into staff_info (staffid, infoid,indexs) values (?, ?, ?)");
		query.setInteger(0, 2);
		query.setInteger(1, 2);
		query.setInteger(2, i);
		query.executeUpdate();
	}

}
